Skip to content

Conversation

@joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 21, 2025

Fixes TOOL-4554


PR-Codex overview

This PR focuses on fixing an issue in the useSiweAuth hook related to the authentication process by ensuring that a chain switch is only triggered when the chain_id in the payload is different from the current chain.

Detailed summary

  • Updated the condition in useSiweAuth.ts to check if payload.chain_id is both present and different from the current chain.id before calling activeWallet.switchChain.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes
    • Improved the SIWE (Sign-In with Ethereum) authentication process by preventing unnecessary chain switching, resulting in a smoother and more efficient authentication flow.

@vercel
Copy link

vercel bot commented May 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:10am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:10am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:10am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:10am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 2:10am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 21, 2025

Walkthrough

The update modifies the SIWE authentication flow in the "thirdweb" component by refining the logic that determines whether a chain switch is necessary. Now, the chain switch is only triggered if the payload's chain ID exists and is different from the active wallet's current chain ID, preventing redundant chain switching.

Changes

File(s) Change Summary
.changeset/ten-parrots-poke.md Adds a changeset describing a patch update for improved SIWE chain switch logic.
packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts Refines the condition for switching chains during SIWE authentication to avoid unnecessary calls.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConnectButton
    participant useSiweAuth
    participant Wallet

    User->>ConnectButton: Initiate SIWE authentication
    ConnectButton->>useSiweAuth: Begin authentication
    useSiweAuth->>Wallet: Get current chain ID
    useSiweAuth->>useSiweAuth: Check payload.chainId vs Wallet.chainId
    alt chainId exists and differs
        useSiweAuth->>Wallet: Switch chain
    end
    useSiweAuth->>Wallet: Proceed with authentication
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix SIWE authentication so that ConnectButton works for Coinbase Wallet (TOOL-4554)

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels May 21, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@joaquim-verges joaquim-verges marked this pull request as ready for review May 21, 2025 02:00
@joaquim-verges joaquim-verges requested review from a team as code owners May 21, 2025 02:00
@linear
Copy link

linear bot commented May 21, 2025

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts (1)

100-100: Consider adding a type check for payload.chain_id.

While the fix works correctly, consider adding an explicit check using typeof payload.chain_id !== 'undefined' instead of relying on truthiness, which might fail for chain ID 0 (if that's ever a valid chain ID).

-if (payload.chain_id && Number(payload.chain_id) !== chain.id) {
+if (typeof payload.chain_id !== 'undefined' && Number(payload.chain_id) !== chain.id) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99901dc and c563f88.

📒 Files selected for processing (2)
  • .changeset/ten-parrots-poke.md (1 hunks)
  • packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
.changeset/ten-parrots-poke.md (1)

1-6: Changeset description is clear and accurately describes the fix.

The changeset correctly identifies the issue being fixed (unnecessary chain switching during SIWE auth) and provides a concise explanation. This is appropriate for a patch-level change.

packages/thirdweb/src/react/core/hooks/auth/useSiweAuth.ts (1)

100-104: Fix looks good - prevents unnecessary chain switching.

The conditional now properly checks both for the existence of payload.chain_id and whether it differs from the current chain's ID before initiating a chain switch. This addresses the original issue of forcing unnecessary chain switches during SIWE authentication.

Before this change, a chain switch would be triggered whenever payload.chain_id existed, even if the user was already on the correct chain.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 56.57 KB (0%) 1.2 s (0%) 247 ms (+43.3% 🔺) 1.4 s
thirdweb (cjs) 309.52 KB (0%) 6.2 s (0%) 1.5 s (+2.89% 🔺) 7.7 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 56 ms (+229.4% 🔺) 170 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 27 ms (+673.27% 🔺) 37 ms
thirdweb/react (minimal + tree-shaking) 19.5 KB (0%) 390 ms (0%) 77 ms (+158.81% 🔺) 467 ms

@codecov
Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 55.59%. Comparing base (99901dc) to head (c563f88).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../thirdweb/src/react/core/hooks/auth/useSiweAuth.ts 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7104   +/-   ##
=======================================
  Coverage   55.59%   55.59%           
=======================================
  Files         901      901           
  Lines       58121    58121           
  Branches     4064     4064           
=======================================
  Hits        32313    32313           
  Misses      25703    25703           
  Partials      105      105           
Flag Coverage Δ
packages 55.59% <0.00%> (ø)
Files with missing lines Coverage Δ
.../thirdweb/src/react/core/hooks/auth/useSiweAuth.ts 42.52% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges merged commit 30fafd1 into main May 21, 2025
26 of 27 checks passed
@joaquim-verges joaquim-verges deleted the _SDK_Fix_SIWE_auth_forcing_unnecessary_chain_switch branch May 21, 2025 06:28
@joaquim-verges joaquim-verges mentioned this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants